package com.gmall.product.controller;

import com.gmall.common.result.PageInfo;
import com.gmall.common.result.Result;
import com.gmall.model.product.SkuInfo;
import com.gmall.product.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/product/sku")
public class SkuController {

    @Autowired
    SkuService skuService;

    @PostMapping("/findPage/{pageNo}/{pageSize}")
    public Result<PageInfo<SkuInfo>> findPage(
            @PathVariable Integer pageNo,
            @PathVariable Integer pageSize,
            @RequestBody Map<String,String> searchMap){
        return skuService.findPage(pageNo,pageSize,searchMap);
    }

    @GetMapping("getSkuInfoById/{id}")
    public Result<SkuInfo> getSkuInfoById(@PathVariable Long id) {

        return skuService.getSkuInfoById(id);
    }


    @GetMapping("/onSale/{skuId}")
    public Result<String> onSale(@PathVariable Long skuId) {
        return skuService.onSale(skuId);
    }

    @GetMapping("/cancelSale/{skuId}")
    public Result<String> cancelSale(@PathVariable Long skuId) {
        return skuService.cancelSale(skuId);
    }


    @PostMapping("getSkuInfoListAfterDateTime")
    public List<SkuInfo> getSkuInfoListAfterDateTime(@RequestBody Map searchMap) {

        return skuService.getSkuInfoListAfterDateTime(searchMap);
    }
}
